/*
 * $Id: RequestScheduleDAO.java,v 1.4 2009/07/24 18:27:43 oliver Exp $
 *
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 *
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */

package com.ge.healthcare.autosc.common.database.dao;

import java.util.ArrayList;
import java.util.List;

import com.ge.healthcare.autosc.common.ASCLogger;
import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.CfgRequestSchedule;

/**
 * @author 212042946
 * 
 */
public class RequestScheduleDAO extends BaseDAO implements IRequestScheduleDAO {
	/**
	 * Eclispe generated
	 */
	private static final long serialVersionUID = -8234283279516707582L;

	private static final String TABLE_NAME = "com.ge.healthcare.autosc.common.database.pojo.CfgRequestSchedule";

	private static final String COL_REQUEST_SCHEDULE_ID = "requestScheduleId";

	public RequestScheduleDAO() {
		super(TABLE_NAME);
	}

	public CfgRequestSchedule getRequestScheduleByID(Long requestScheduleId) {
		Object requestSchedule = findObjectByID(COL_REQUEST_SCHEDULE_ID,
				requestScheduleId);
		if (!ASCUtil.isNullOrEmptyObject(requestSchedule)) {
			return (CfgRequestSchedule) requestSchedule;
		}
		return null;
	}

	public List<CfgRequestSchedule> getAllRequestSchedule() {
		String queryString = "from " + TABLE_NAME;
		ASCLogger.debug(this.getClass(), "getAllRequestSchedule",
				new StringBuffer().append(queryString));
		List<?> rtvdSchedules = getHibernateTemplate().find(queryString);
		if (ASCUtil.isNullOrEmptyList(rtvdSchedules)) {
			return null;
		}
		List<CfgRequestSchedule> requestScheduleLst = new ArrayList<CfgRequestSchedule>();
		for (Object schedule : rtvdSchedules) {
			requestScheduleLst.add((CfgRequestSchedule) schedule);
		}
		return requestScheduleLst;
	}

	public List<CfgRequestSchedule> getPastDueRequestSchedule() {
		StringBuffer queryString = new StringBuffer("from ")
				.append(TABLE_NAME)
				.append(
						" where sysdate - (run_interval_in_hr/24) >= last_time_run");
		ASCLogger.debug(this.getClass(), "getAllRequestSchedule", queryString);
		List<?> rtvdSchedules = getHibernateTemplate().find(
				queryString.toString());
		if (ASCUtil.isNullOrEmptyList(rtvdSchedules)) {
			return null;
		}
		List<CfgRequestSchedule> requestScheduleLst = new ArrayList<CfgRequestSchedule>();
		for (Object schedule : rtvdSchedules) {
			requestScheduleLst.add((CfgRequestSchedule) schedule);
		}
		return requestScheduleLst;

	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#save(java.lang.Object)
	 */
	public void save(Object pojo) {
		super.save(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.IRequestTypeDAO#saveAlways(java.lang.Object)
	 */
	public void saveAlways(Object pojo) {
		super.save(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#deleteByID(java.lang.Object)
	 */
	public void deleteByID(Object pojo) {
		super.deleteByID(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#refresh(java.lang.Object)
	 */
	public void refresh(Object pojo) {
		super.refresh(pojo);
	}
}
